<?php

/*
 * formation/load-index.phtml
 */
?>
<?php
$formations = $this->formations;
?>
<div class="list-container">
    <table class="table table-striped list-table">
	<thead>
	    <tr>
		
		<td width="45%">Libellé</td>
		<td width="45%">Description</td>
		<td width="10%">&nbsp;</td>
	    </tr>
	</thead>
	<tbody>
	    <?php foreach ($formations as $d): ?>
    	    <tr>
    		
    		<td>
		    <a href="#" class="edit-formation" data-type="text" data-pk="<?php echo $d->id; ?>" data-name="libelle"><?php echo $d->libelle; ?></a>
    		</td>
    		<td>
		    <a href="#" class="edit-formation" data-type="text" data-pk="<?php echo $d->id; ?>" data-name="description"><?php echo $d->description; ?></a>
    		</td>
		<td>
    		    <a href='#' data-id="<?php echo $d->id; ?>" data-libelle="<?php echo $d->libelle; ?>" class="delete-formation">
    			<img src='<?php echo $this->basePath() . '/img/rhx/delete-16x16.png' ?>' alt='Effacer' title='Effacer'>
    		    </a>
    		</td>
    	    </tr>
	    <?php endforeach; ?>
	</tbody>
    </table>
</div>

<script type="text/javascript">
// Démarrage
$(function(){
    // Editable
    $('.edit-formation').editable({
	title: 'Edition de la Formation',
	url: '<?php echo $this->url('RHX/default', array('controller'	 => 'formation', 'action'	 => 'edit')); ?>'
    });
    $('.delete-formation').click(function(e){
	e.preventDefault();
	libelle = $(this).attr('data-libelle');
	id = $(this).attr('data-id');
	if(!confirm("Voulez-vous effacer la formation '" + libelle + "' ?")){
	    return false;
	}
	ajax = $.ajax({
	    type: 'post',
	    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'formation', 'action'	 => 'erase')) ?>',
	    data: '&id=' + id
	});
	ajax.done(function(result){
	    if(!result.done){
		alert("Une erreur est survenue !");
	    }
	    refresh();
	});
    });
});
</script>
